{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>编辑</h5>
                </div>
                <div class="ibox-content layui-form">
                    <div class="layui-row layui-col-space10 layui-form-item ">
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">资料名称：</label>
                            <div class="layui-input-block">
                                <input type="text" name="cpd_name" value="{$info.cpd_name}" class="layui-input" lay-verify="required" maxlength="30" >
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">所属企业：</label>
                            <div class="layui-input-block">
                                <input type="text" name="c_name" value="{$info.c_name}" class="layui-input" disabled>
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">所属产品：</label>
                            <div class="layui-input-block">
                                <input type="text" name="cp_name" value="{$info.cp_name}" class="layui-input" disabled>
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8 form-group">
                            <label class="layui-form-label">资料类型：</label>
                            <div class="layui-input-block">
                                <select name="cpd_type" lay-filter="role">
                                    <option value="1" {if $info.cpd_type==1}selected{/if}>图片</option>
                                    <option value="2" {if $info.cpd_type==2}selected{/if}>文档</option>
                                    <option value="3" {if $info.cpd_type==3}selected{/if}>视频</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8 {$info.cpd_type==1 ? '' : 'hidden'}" id="image_1">
                            <label class="layui-form-label">图片：</label>
                            <div class="layui-input-block">
                                <input type="hidden" name="del" id="del2" value="">
                                <input type="hidden" id="hid2" value="{$info.cpd_type==1 ? $info.cpd_content : ''}">
                                <input type="hidden" name="cpd_content1" id="photo2" value="{$info.cpd_type==1 ? $info.cpd_content : ''}">
                                <div id="uploader2" class="container-s">
                                    <div class="queueList">
                                        <div class="placeholder">
                                            <div id="filePicker2"></div>
                                            <p>或将图片拖到这里</p>
                                        </div>
                                    </div>
                                    <div class="statusBar" style="display:none;">
                                        <div class="layui-progress layui-progress-big active-s" lay-showpercent="true">
                                            <div class="layui-progress-bar layui-bg-blue" lay-percent="0%">
                                            </div>
                                            <span></span>
                                        </div>
                                        <div class="info"></div>
                                        <div class="btns">
                                            <div id="goPicker2" class="filePicker2"></div>
                                            <div class="uploadBtn">开始上传</div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8 {$info.cpd_type==2 ? '' : 'hidden'}" id="pdf_2">
                            <label class="layui-form-label">文档：</label>
                            <input type="hidden" name="cpd_content2" id="lay-img" lay-verify="image" value="{$info.cpd_type==2 ? $info.cpd_content : ''}">
                            <div class="layui-input-block">
                                <div id="lay-upload">上传PDF</div>
                                <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
                                    文件地址：
                                    <div class="layui-upload-list" id="lay-list">
                                        {if $info.cpd_type==2}
                                        {$info.cpd_content}
                                        {/if}
                                    </div>
                                </blockquote>
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8 {$info.cpd_type==3 ? '' : 'hidden'}" id="video_3">
                            <label class="layui-form-label">视频：</label>
                            <input type="hidden" name="cpd_content3" id="lay-img2" lay-verify="image" value="{$info.cpd_type==3 ? $info.cpd_content : ''}">
                            <div class="layui-input-block">
                                <div id="lay-upload2">上传视频</div>
                                <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
                                    预览：
                                    <div class="layui-upload-list" id="lay-list2">
                                        {if $info.cpd_type==3}
                                        <video class="layui-append-img" src="{$info.cpd_content}" controls="controls"></video>
                                        {/if}
                                    </div>
                                </blockquote>
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">缩略图：</label>
                            <input type="hidden" name="cpd_thumb" id="lay-img3" value="">
                            <div class="layui-input-block">
                                <div id="lay-upload3">上传图片</div>
                                <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
                                    预览图：
                                    <div class="layui-upload-list" id="lay-list3">
                                        <img class="layui-append-img" src="{$info.cpd_thumb}" onerror="this.src='/static/admin/images/no_img.jpg'">
                                    </div>
                                </blockquote>
                                <span style="color: gray">可自定义缩略图，如不传，图片类型截取第一张为缩略图，文档类型默认固定缩略图，视频类型截取第一帧为缩略图</span>
                            </div>

                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">开放区域：</label>
                            <div class="layui-input-block">
                                <div id="demo1" class="xm-select-demo"></div>
                            </div>
                            <div class="layui-input-inline">
                                <input type="text" disabled style="border: none;color: gray;font-size: 12px;" class="layui-input" value="不选默认全国" />
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">浏览量：</label>
                            <div class="layui-input-block">
                                <input type="text" name="cpd_browse" value="{$info.cpd_browse}" class="layui-input" lay-verify="required" >
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">排序值：</label>
                            <div class="layui-input-block">
                                <input type="number" placeholder="值越大越靠前" name="cpd_sort" value="{$info.cpd_sort}" maxlength="11" class="layui-input" lay-verify="number" >
                            </div>
                        </div>
                        <input type="hidden" value="{$info.cpd_id}" name="cpd_id">
                        <input type="hidden" id='can' value="{$info.cpd_type}">
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit="" lay-filter="component-form-element">保存
                                </button>
                                <button class="layui-btn layui-btn-primary" onclick="wk.layer_close('close')">关闭</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer" /}
</body>
</html>
<script>
    var ptype = $('#can').val();
    if(ptype == 1){
        var n2 = wk.uploads({num:10,type:'png,jpg,jpeg',attr:2,status:'update'})
        function imgDel2(e,obj,hid,del){
            wk.update_del(e,obj,hid,del,n2);
        }
    }
    wk.uploadImg({size:5,type:'PDF,pdf',url:"{:url('Upload/upload')}",video:2}); //文档
    wk.uploadImg({size:500,num:2,type:'MP4,Mp4,mP4,mp4',url:"{:url('Upload/upload')}",video:3}); //视频
    wk.uploadImg({size:5,num:3,type:'png,jpg,jpeg',url:"{:url('Upload/upload')}"}); //缩略图
    layui.use(['form','upload','layedit'], function() {
        var form = layui.form;
        form.on('submit(component-form-element)', function (data) {
            $('.layui-btn').addClass('layui-disabled').attr('disabled','disabled');
            $.ajax({
                url:"{:url('editData')}",
                type:'post',
                dataType:'json',
                data:data.field,
                success:function(res){
                    if (res.code == 200) {
                        layer.msg(res.msg,{icon:1,time:1500,shade:0.1},function(index){
                            wk.layer_close();
                        })
                    } else {
                        wk.error(res.msg,'','$(".layui-btn").removeClass(\'layui-disabled\').removeAttr(\'disabled\');');
                    }
                }
            })
        });
        form.on('select(role)', function(data){
            if(data.value == 1){
                $('#image_1').removeClass('hidden');
                $('#pdf_2').addClass('hidden');
                $('#video_3').addClass('hidden');
                //
                var n = wk.uploads({num:10,attr:2,type:'png,jpg,jpeg',url:"{:url('admin/upload/upload')}"}); //图片
                function imgDel(e,obj){
                    wk.uploads_del(e,obj,n); // 删除
                }
            }else if(data.value == 2){
                $('#pdf_2').removeClass('hidden');
                $('#image_1').addClass('hidden');
                $('#video_3').addClass('hidden');
                //
                wk.uploadImg({size:5,type:'PDF,pdf',url:"{:url('Upload/upload')}",video:2}); //文档
            }else{
                $('#video_3').removeClass('hidden');
                $('#pdf_2').addClass('hidden');
                $('#image_1').addClass('hidden');
                //
                wk.uploadImg({size:500,num:2,type:'MP4,Mp4,mP4,mp4',url:"{:url('Upload/upload')}",video:3}); //视频
            }
        });
    });
    var demo1 = xmSelect.render({
        el: '#demo1',
        autoRow: true,
        name: 'cpd_sheng',
        cascader: {
            show: true,
            indent: 200,
        },
        data(){
            return {$province}
        }
    })
</script>